package com.cyh.core.framework.domain.dto;


import java.util.Collection;
import java.util.Map;

public class ResultDTO<T> {
    private boolean success;

    private int status;

    private int count;

    private T data;

    private String msg;

    private ResultDTO() {
    }

    public static ResultDTO  Success(){
        return new ResultDTO(true,200);
    }

    public static ResultDTO  Success(String msg){
        return new ResultDTO(true,200,msg);
    }

    public static ResultDTO  Success(Object data){
        return new ResultDTO(true,200,data);
    }

    public static ResultDTO  Success(Object data,int count){
        return new ResultDTO(true,200,data,count);
    }

    public static ResultDTO  Success(String msg,Object data){
        return new ResultDTO(true,200,data,msg);
    }

    public static ResultDTO  Success(String msg,Object data,int count){
        return new ResultDTO(true,200,data,msg,count);
    }

    public static ResultDTO  Failure(int status){
        return new ResultDTO(false,status);
    }

    public static ResultDTO  Failure(int status,String msg){
        return new ResultDTO(false,status,msg);
    }

    public static ResultDTO  Failure(int status,Object data){
        return new ResultDTO(false,status,data);
    }

    public static ResultDTO  Failure(int status,Object data,int count){
        return new ResultDTO(false,status,data,count);
    }

    public static ResultDTO  Failure(int status,String msg,Object data){
        return new ResultDTO(false,status,data,msg);
    }

    public static ResultDTO  Failure(int status,String msg,Object data,int count){
        return new ResultDTO(false,status,data,msg,count);
    }

    public ResultDTO(boolean success, int status, T data, String msg,int count) {
        this.success = success;
        this.status = status;
        this.data = data;
        this.count=count;
        this.msg = msg;
    }

    public ResultDTO(boolean success, int status, T data, String msg) {
        this.success = success;
        this.status = status;
        this.data = data;
        this.msg = msg;
        if(data instanceof Collection){
            Collection datac= (Collection) data;
            count=datac.size();
        }else if(data instanceof Map){
            count=1;
        }
    }

    public ResultDTO(boolean success, int status, String msg) {
        this.success = success;
        this.status = status;
        this.msg = msg;
    }

    public ResultDTO(boolean success, int status, T data,int count) {
        this.success = success;
        this.status = status;
        this.data = data;
        this.count=count;
    }

    public ResultDTO(boolean success, int status, T data) {
        this.success = success;
        this.status = status;
        this.data = data;
        if(data instanceof Collection){
            Collection datac= (Collection) data;
            count=datac.size();
        }else if(data instanceof Map){
            count=1;
        }
    }

    public ResultDTO(boolean success, int status) {
        this.success = success;
        this.status = status;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public String toString() {
        return "{" +
                "\"success\":" + success +
                ",\"status\":" + status +
                ",\"data\":" + data +
                ",\"msg\":\"" + msg +
                "\",\"count\":" + count +
                "}";
    }
}
